#ifndef _FSMGR_H_
#define _FSMGR_H_

#include "../Common/AllTool.h"
#include "FileNode.h"

int BroadCommandToChunk(COMMAND &cmd);

#define FN_END_STRING	(_TEXT("END_OF_DIR"))
#define FN_HEAD_STRING	(_TEXT("DISK_FILE_V1.0"))

#define FN_NOT_FOUND (-1)
class FsMgr
{
private:
	UINT64		uFileGuid;
	tstring		tsDiskFile;
	FileNode	*pRoot;

	void CreateRoot();
	void FreeNode(FileNode *pNode);
	void VisitNode(FILE *fp,FileNode *pNode);
	void ConstructNode(FILE *fp,FileNode *pFather);
	
public:
	tstring		tsDiskName;
	FsMgr();
	FsMgr(tstring strFilename);
	~FsMgr();
	UINT64 GetFileGuid()
	{
		return ++uFileGuid;
	}
	int Find(tstring tsFilename,FileNode *&pfnFile);
	int DeleteIt(FileNode *pfnDir,tstring tsName);
	int DeleteIt(tstring tsFilename);
	int SetFileEnd(tstring tsFilename,UINT64 uOffset);
	static int GetFilePath(tstring tsFilename,tstring &tsPath);
	static int GetFileName(tstring tsFilename,tstring &tsName);
	int LoadFromFile(tstring strFilename);
	int SaveToFile(tstring strFilename);
	std::map<UINT64,std::vector<int> *> mLocation;
};



#endif